package com.cskaoyan.exception;

import com.cskaoyan.bean.BaseRespVo;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

/**
 * 统一异常处理
 * 创建日期: 2022/04/07 16:39
 *
 * @author HanWeiqi
 */
@RestControllerAdvice
public class ExceptionControllerAdvice {
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public BaseRespVo httpMessageNotReadableException(HttpMessageNotReadableException exception) {
        exception.printStackTrace();
        return BaseRespVo.fail(401,"请检查参数是否输入正确");
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public BaseRespVo MethodArgumentNotValidException(MethodArgumentNotValidException exception) {
        exception.printStackTrace();
        return BaseRespVo.fail(401,"请按要求输入");
    }

    @ExceptionHandler(IncorrectCredentialsException.class)
    public BaseRespVo IncorrectCredentialsException(IncorrectCredentialsException exception) {
        exception.printStackTrace();
        return BaseRespVo.fail(700,"用户名或密码输入错误");
    }


    @ExceptionHandler(MethodArgumentTypeMismatchException.class)
    public BaseRespVo methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) {
        exception.printStackTrace();
        return BaseRespVo.fail(10000, "请输入正确的数据类型");
    }




//    @ExceptionHandler(NullPointerException.class)
//    public BaseRespVo nullPointerException(NullPointerException exception) {
//        return BaseRespVo.fail(102,"需要登录账号哦亲亲");
//    }
}
